/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
function formValidate() {
    var sendMes = '';
    var required = $("#required").prop("checked");
    var type = $("input[name='type']:checked").val();
    var way = $("input[name='way']:checked").val();
    var minv = $("input[name='min']").val();
    var maxv = $("input[name='max']").val();
    var set = $("input[name='set']").val();
    var suf = '|';
    var message = '';
    if (required) {
        sendMes += 'required' + suf;
        message += '必填'+suf;
    }
    if (type) {
        sendMes += type + suf;
        message += '必须为'+type+'类型'+suf;
    }
    if (way === '1') {
        $("input[name='set']").removeAttr("required");
        if (minv === '' && maxv === '') {
            showError('请输入范围值');
            return false;
        }
        var min = Number(minv);
        var max = Number(maxv);
        if ( min === max && (min > max)) {
            showError('数值范围错误');
            return false;
        }
        if (minv) {
            sendMes += "min:" + minv + suf;
            message += '最小等于'+minv+suf;
        }
        if (maxv) {
            sendMes += "max:" + maxv + suf;
            message += '最大等于'+maxv+suf;
        }
    } else if (way === '2') {
        if (set === '') {
            showError('请输入集合');
            return false;
        }
        var setlen = set.length;
        var endw = set.substring(setlen - 1);
        if (endw === ',') {
            set = set.substring(0, setlen - 1);
        }
        sendMes += 'in:[' + set + ']' + suf;
        message += '需在['+set+']中'+suf;
    }
    var endMes = sendMes.substring(0, sendMes.length - 1);
    var mes = message.substring(0, message.length-1);
    $('#myform').append("<input name='validate' type='hidden' value='" + endMes + "' /><input name='message' type='hidden' value='" + mes + "'/>");
}
$("input[name='way']").click(function () {
    var check = $(this).attr("data-checked");
    //把所有的radio属性data-checked设置成0
    $("input[name='way']").attr("data-checked", 0);
    //判断是否是选中状态
    if (check === '1') {
        //选中状态
        $(this).prop("checked", false);
        $(this).attr("data-checked", 0);
    } else {
        $(this).attr("data-checked", 1);
    }
});
function showError(msg) {
    art.dialog({
        content: msg,
        icon: 'warning',
        ok: function () {
            return true;
        }
    });
}


